﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orion.Models;
using Orion.MyLib;

namespace Orion.Controllers
{
    public class WorkController : Controller
    {
		[Authorize]
        public ActionResult Index()
        {
			return View( );
        }

		[Authorize(Roles = "Admin, Staff")]
		public ActionResult SendMassEmail()
		{
			var model = new EmailMessage();

			return View(model);
		}

		[Authorize(Roles = "Admin, Staff")]
		[HttpPost]
		public ActionResult SendMassEmail( EmailMessage em )
		{
			try
			{
				var emailService = new EmailService();
				var emailListRep = new EmailListRepository();
				var emailList = emailListRep.GetAllEmail();

				//send email for each emailadress in emaillist
				foreach (var email in emailList)
				{
					emailService.SendMessage( em );
				}

				return RedirectToAction("Index", "Work");
			}
			catch ( Exception ex )
			{
				var log = new Logger();
				log.LogExcepion(ex);
				return View("Error");
			}
			
		}
    }
}
